<template>
  <div class="app-container">
    <el-row>
      <el-col :span="24">
        <div class="h_top">
          <div class="bread_title">
            <span>提交采购申请</span>
          </div>
          <div class="add_button">
            <div class="buttonBox">
              <el-button type="primary" icon="el-icon-document-checked" size="mini" @click="save">保存</el-button>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <div>
      <el-row>
        <el-col :span="24">
          <el-form ref="form" :model="data" :inline="true" class="pt20" :rules="formRules">
            <el-row :gutter="10">
              <el-col :xl="3" :lg="3" :md="5" :sm="6">
                <el-form-item prop="coding">
                  <div>编号</div>
                  <el-input v-model="data.coding" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :xl="3" :lg="3" :md="5" :sm="6">
                <el-form-item prop="name">
                  <div>名称</div>
                  <el-input v-model="data.name" size="mini" />
                </el-form-item>
              </el-col>
              <el-col :xl="4" :lg="4" :md="5" :sm="6">
                <el-form-item prop="factory_id">
                  <div>所属工厂</div>
                  <v-select v-model="data.factory_id" action="factoryList" />
                </el-form-item>
              </el-col>
              <el-col :xl="3" :lg="3" :md="5" :sm="6">
                <el-form-item prop="admin_id">
                  <div>申请人员</div>
                  <v-select v-model="data.admin_id" />
                </el-form-item>
              </el-col>
              <el-col :xl="3" :lg="3" :md="5" :sm="6">
                <el-form-item prop="status">
                  <div>状态</div>
                  <el-select v-model="data.status" size="mini">
                    <el-option v-for="(item, index) in applyStatus" :key="index" :value="index" :label="item" :disabled="true" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :xl="3" :lg="3" :md="5" :sm="6">
                <el-form-item prop="kind">
                  <div>采购物品</div>
                  <el-select v-model="data.kind" size="mini">
                    <el-option v-for="(item, index) in applyKind" :key="index" :value="index+1" :label="item" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :xl="3" :lg="3" :md="5" :sm="6">
                <el-form-item prop="sort">
                  <div>排序</div>
                  <el-input v-model="data.sort" size="mini" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <el-tabs>
            <el-tab-pane label="描述">
              <el-row :gutter="10">
                <el-col :span="24">
                  <wangeditor id="content" v-model="data.content" />
                </el-col>
              </el-row>
            </el-tab-pane>
          </el-tabs>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import API from '@/api/procurement/applyfor'
import Wangeditor from '@/components/editor/wangeditor'
import { applyStatus, applyKind } from '@/utils/options'
import VSelect from '@/components/select'
export default {
  inject: ['addOne'],
  components: {
    VSelect,
    Wangeditor
  },
  data() {
    return {
      data: {
        coding: '',
        name: '',
        status: 0,
        sort: 100
      },
      applyStatus,
      applyKind,
      formRules: {
        coding: [
          {
            required: true,
            message: '请输入编号',
            trigger: 'blur'
          }
        ],
        name: [
          {
            required: true,
            message: '请输入申请单名称',
            trigger: 'blur'
          }
        ],
        factory_id: [
          {
            required: true,
            message: '请选择工厂',
            trigger: 'change'
          }
        ],
        admin_id: [
          {
            required: true,
            message: '请选择申请人员',
            trigger: 'change'
          }
        ],
        status: [
          {
            required: true,
            message: '请选择状态',
            trigger: 'change'
          }
        ],
        sort: [
          {
            required: true,
            message: '请输入排序',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  created() {},
  methods: {
    save() {
      const thisData = this.data
      const thisForm = this.$refs.form
      this.addOne(API, thisData, thisForm)
    }
  }
}
</script>
